import requests

from api.api_test_login import TestLogin
from common.ihrm_get_header import get_headers
from common.log_util import init_logger

logger = init_logger("log/ihrm.log")
class TestAddEmp(object):
    @classmethod
    def test_add(cls, body):
        # token = "Bearer " + TestLogin.test_login(body).json().get("data")
        url_add = "http://ihrm-test.itheima.net/api/sys/user"
        logger.debug(f"这是请求体的url:{url_add}")
        # headers = {"Content-Type": "application/json", "Authorization": tok}
        headers = get_headers()
        resp = requests.post(url_add, headers=headers, json=body)
        return resp
    @classmethod
    def query_one(cls,headers,id):
        url_query = "http://ihrm-test.itheima.net/api/sys/user" + "/" + id
        re = requests.get(url_query, headers=headers)
        return re
    @classmethod
    def modify_one(cls,headers,id,body_modify):
        url_modify = "http://ihrm-test.itheima.net/api/sys/user" + "/" + id
        r = requests.put(url_modify,headers=headers,json = body_modify)
        return r
    @classmethod
    def delete_one(cls,headers,id):
        url_de = "http://ihrm-test.itheima.net/api/sys/user" + "/" + id
        wu = requests.delete(url_de,headers=headers)
        return wu
# if __name__ == '__main__':
   # token = "Bearer " + TestLogin.test_login().json().get("data")
    # headers = {"Content-Type": "application/json", "Authorization": token}
    # # body = {"mobile": "13800000002", "password": "123456"}
    # body_qu = {"username": "DB01", "mobile": "17591088989", "workNumber": "123"}
    # a = TestAddEmp.test_add(body_qu)
    # id = a.json().get("data").get("id")
    # b = TestAddEmp.query_one(headers,id)
    # print(b.json())
    #
    # body_modify = {"username": "DB01", "password": "123456", "departmentId": "10086"}
    # c = TestAddEmp.modify_one(headers,id ,body_modify)
    # print(c.json())
    #
    # d = TestAddEmp.delete_one(headers,id)
    # print(d.json())



